from matplotlib import pyplot
print('本程序可以帮助你绘制幂函数y=x^a的图像')
a = input('请输入a的值:')
a = float(a)
x_list1 = []
y_list1 = []
x_list2 = []
y_list2 = []

for i in range(-10, 0):
    for j in range(100):
        x = i + j * 0.01
        if x == 0 and a <= 0:  # 如果a<=0，0不在定义域内，舍去
            continue
        y = pow(x, a)
        if isinstance(y, complex):
            continue
        if y > 10:
            continue
        if y < -10:
            continue
        x_list1.append(x)
        y_list1.append(y)
for i in range(0, 10):
    for j in range(100):
        x = i + j * 0.01
        if x == 0 and a <= 0:  # 如果a<=0，0不在定义域内
            continue
        y = x ** a
        if y > 10:
            continue
        if y < -10:
            continue
        x_list2.append(x)
        y_list2.append(y)
pyplot.plot(x_list1, y_list1, color='blue')
pyplot.plot(x_list2, y_list2, color='blue')
pyplot.plot([0, 0], [-10, 10], color='black')  # y轴
pyplot.plot([-10, 10], [0, 0], color='black')  # x轴
pyplot.plot([0], [10], color='black', marker='^')  # y轴箭头
pyplot.plot([10], [0], color='black', marker='>')  # x轴箭头
pyplot.show()
